package com.lagou.common.service;

import com.lagou.common.dao.FlashSaleDao;
import com.lagou.common.pojo.FlashSale;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FlashSaleService {

    @Autowired
    private OrderService orderService;

    @Autowired
    private FlashSaleDao flashSaleDao;

    public List<FlashSale> findAll() {
        return flashSaleDao.findAll();
    }

    public FlashSale findFlashSaleByName(String product) {
        List<FlashSale> flashSaleByName = flashSaleDao.findFlashSaleByName(product);
        if (flashSaleByName.size() == 0) {
            return null;
        } else {
            return flashSaleByName.get(0);
        }
    }

    public void save(FlashSale flashSale) {
        flashSaleDao.save(flashSale);
    }

    public void decreaseOneStock(Long id) {
        flashSaleDao.decreaseOneStock(id);
    }
}
